
import facade.ClienteFacade;
import facade.ProjetoFacade;
import facade.SystemViewRemote;
import java.rmi.RemoteException;
import java.util.Vector;

public class ClienteFrame extends javax.swing.JFrame {
  private SystemViewRemote system;
  private Vector clientes;

  /** Creates new form ClienteFrame */
  public ClienteFrame() {
    initComponents();

    try {
      system = Ejb.getSystemView();
      clientes = new Vector(system.getClientes());

      Vector listData = new Vector();
      for (int i = 0; i < clientes.size(); ++i)
        listData.add(((ClienteFacade)clientes.elementAt(i)).getId());

      clienteList.setListData(listData);
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }
    
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    atualizarButton = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    projetoList = new javax.swing.JList();
    jLabel1 = new javax.swing.JLabel();
    jScrollPane3 = new javax.swing.JScrollPane();
    clienteList = new javax.swing.JList();
    jLabel3 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("ClienteFrame");

    atualizarButton.setText("Atualizar");
    atualizarButton.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        atualizarButtonActionPerformed(evt);
      }
    });

    projetoList.setModel(new javax.swing.AbstractListModel() {
      String[] strings = { " " };
      public int getSize() { return strings.length; }
      public Object getElementAt(int i) { return strings[i]; }
    });
    jScrollPane1.setViewportView(projetoList);

    jLabel1.setText("Projetos:");

    clienteList.setModel(new javax.swing.AbstractListModel() {
      String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
      public int getSize() { return strings.length; }
      public Object getElementAt(int i) { return strings[i]; }
    });
    jScrollPane3.setViewportView(clienteList);

    jLabel3.setText("Clientes:");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel3)
              .addComponent(jLabel1))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE))
              .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(22, Short.MAX_VALUE))
          .addGroup(layout.createSequentialGroup()
            .addComponent(atualizarButton)
            .addContainerGap(276, Short.MAX_VALUE))))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel3)
          .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGap(77, 77, 77)
            .addComponent(jLabel1))
          .addGroup(layout.createSequentialGroup()
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(atualizarButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void atualizarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizarButtonActionPerformed
    int p = clienteList.getSelectedIndex();
    if (p == -1)
      return;

    ClienteFacade cliente = (ClienteFacade)clientes.elementAt(p);
    Vector projetos = new Vector(cliente.getProjetoColletion());

    Vector listData = new Vector();
    for (int i = 0; i < projetos.size(); ++i) {
      ProjetoFacade projeto = (ProjetoFacade)projetos.elementAt(i);
      listData.add(projeto.getId());
    }
  }//GEN-LAST:event_atualizarButtonActionPerformed


  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton atualizarButton;
  private javax.swing.JList clienteList;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JScrollPane jScrollPane3;
  private javax.swing.JList projetoList;
  // End of variables declaration//GEN-END:variables
}
